﻿@using SrBBSPro.Entities
@model SrBBSPro.Entities.Project
@{
    ViewBag.Title = "项目机能一览";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
    var li = ViewBag.Members as List<User>;
    var IsAdmin = Convert.ToBoolean(Session["IsAdmin"]);
}
<div class="main layui-clear">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>项目机能一览</legend>
    </fieldset>
    <div class="layui-form layui-form-pane">
        <div class="wrap">
            <table id="pages" lay-filter="pages"></table>
        </div>
        @if (ViewBag.IsManager || IsAdmin)
        {
            <fieldset class="layui-elem-field">
                <legend>机能明细</legend>
                <div class="layui-field-box">
                    <form method="post">
                        @Html.AntiForgeryToken()
                        <div class="layui-form-item">
                            <input type="hidden" id="Id" name="Id" value="@Model.Id" />
                            <div class="layui-inline">
                                <label class="layui-form-label">机能ID</label>
                                <div class="layui-input-block">
                                    <input id="No" name="No" class="layui-input" required lay-verify="required" />
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">机能名</label>
                                <div class="layui-input-block">
                                    <input id="PageName" name="PageName" class="layui-input" required lay-verify="required" />
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">规模</label>
                                <div class="layui-input-block">
                                    <input id="Scale" name="Scale" type="number" class="layui-input" required lay-verify="number" placeholder="单位:KL" />
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">开发担当</label>
                                <div class="layui-input-block" style="width:182px">
                                    <select id="Developer" name="Developer" required lay-verify="required">
                                        <option value="">请选择</option>
                                        @foreach (var item in li)
                                        {
                                            <option value="@item.Id">@item.StaffName</option>
                                        }
                                    </select>
                                    <input type="hidden" id="DeveloperName" name="DeveloperName" />
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">测试担当</label>
                                <div class="layui-input-block" style="width:182px">
                                    <select id="Tester" name="Tester" required lay-verify="required">
                                        <option value="">请选择</option>
                                        @foreach (var item in li)
                                        {
                                            <option value="@item.Id">@item.StaffName</option>
                                        }
                                    </select>
                                    <input type="hidden" id="TesterName" name="TesterName" />
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">修正担当</label>
                                <div class="layui-input-block" style="width:182px">
                                    <select id="Reviser" name="Reviser" required lay-verify="required">
                                        <option value="">请选择</option>
                                        @foreach (var item in li)
                                        {
                                            <option value="@item.Id">@item.StaffName</option>
                                        }
                                    </select>
                                    <input type="hidden" id="ReviserName" name="ReviserName" />
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">状态</label>
                                <div class="layui-input-block" style="width:182px">
                                    <select id="Status" name="Status" class="layui-input" required lay-verify="required">
                                        <option value="">请选择</option>
                                        <option value="0">确认中</option>
                                        <option value="1">完了</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">备注</label>
                                <div class="layui-input-block" style="width:490px">
                                    <input id="Remark" name="Remark" class="layui-input" />
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="addPage">信息提交</button>
                        </div>
                    </form>
                </div>
            </fieldset>
        }
    </div>
    <script type="text/html" id="toolbarDemo">
        <b>@Model.Name 机能一览</b>
    </script>
    <script type="text/html" id="barDemo">
        @if (ViewBag.IsManager || IsAdmin)
        {
            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        }
    </script>
</div>
@section scripts{
    <script>
        layui.use(['jquery', 'form', 'table'], function () {
            var table = layui.table;
            var $ = layui.jquery;
            var form = layui.form;
            var pid = '@Model.Id';
            table.render({
                elem: '#pages'
                , height: 400
                , title: '项目机能一览'
                , page: {

                }
                , url: '/Project/PageDataList?hid='+pid
                , autoSort: false
                , toolbar: '#toolbarDemo'
                , defaultToolbar: ['filter', 'exports', 'print']
                , cols: [[
                    { type: 'numbers' }
                    , { field: 'No', title: '机能ID', width: 150 }
                    , { field: 'PageName', title: '机能名', width: 240 }
                    , { field: 'Scale', title: '規模', width: 80, templet: '<span>{{ d.Scale }} KL</span>'}
                    , { field: 'DeveloperName', title: '开发担当', width: 100 }
                    , { field: 'Developer', hide: true }
                    , { field: 'TesterName', title: '测试担当', width: 100 }
                    , { field: 'Tester', hide: true }
                    , { field: 'ReviserName', title: '修正担当', width: 100 }
                    , { field: 'Reviser', hide: true }
                    , { field: 'StatusName', title: '状态', width: 80 }
                    , { field: 'Status', hide: true }
                    , { field: 'Remark', title: '备注', width: 160 }
                    , { field: 'DelBtn', fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150 }
                ]]
            });

            table.on('tool(pages)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('确定要删除该行数据吗？', function (index) {
                        getPost('/Project/DelPage', { pid: pid,sno:data.No }, function () {
                            if (res.status == 0) {
                                layer.msg("删除成功", { icon: 5 });
                                obj.del();
                                layer.close(index);
                            } else if (res.status == 1) {
                                layer.msg(res.msg, { icon: 5 });
                            }
                        });
                    });
                } else if (obj.event === 'edit') {
                    $("#No").val(data.No);
                    $("#PageName").val(data.PageName);
                    $("#Scale").val(data.Scale);
                    $("#DeveloperName").val(data.DeveloperName);
                    $("#Developer").val(data.Developer);
                    $("#TesterName").val(data.TesterName);
                    $("#Tester").val(data.Tester);
                    $("#ReviserName").val(data.ReviserName);
                    $("#Reviser").val(data.Reviser);
                    $("#Status").val(data.Status);
                    $("#Remark").val(data.Remark);
                    form.render();
                }
            });

            form.on('submit(addPage)', function (data) {
                $.post('@Url.Action("AddPage","Project")', data.field, function (res) {
                    if (res.status==1) {
                        layer.msg(res.msg, { icon: 2 });
                    } else {
                        layer.msg(res.msg, { icon: 1,time:1000 }, function (index) {
                            layer.close(index);
                            table.reload('pages', {
                                page: { curr: 1 }
                                , url: '/Project/PageDataList?hid=' +pid
                            });
                        });
                    }
                }, 'json');
                return false;
            });
        })
    </script>
}